﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MarkdownSharp;

namespace IFWiki.Utils
{
    public static class String
    {
        /// <summary>
        /// Convert markdown to html
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static string ToHtml(this string markDown)
        {
            return (new Markdown()).Transform(markDown);
        }


        /// <summary>
        /// Convert multi line into single line
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static string ToSingleLine(this string input)
        {
            if (string.IsNullOrEmpty(input)) return input;

            return input.Replace("\n","").Replace("\r","");
        }


        /// <summary>
        /// Cleans the specified source, turning it into an acceptable filename.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static string Clean(this string source)
        {
            if (string.IsNullOrEmpty(source)) return source;
            return source.Replace(' ', '_').Replace("|","_bar_").Replace(":","_colon_");
        }
    }
}
